import { BaseEasyuiComp } from './baseEasyuiComp';
import { COMPTYPE, CONSTKEY, convertArgToArray } from '../utils';

export class EasyuiMessager extends BaseEasyuiComp{ 
    constructor(params, componentConfig){ 
        super('messager', Object.getOwnPropertyNames($.messager.defaults),  componentConfig); 
        this.bindMethods();
    }
    private bindMethods(){
        var keys = this.getMethodKeys();
        keys.forEach(key => {
            this[key] = ()=>{
                let args = convertArgToArray.call(arguments);
                $.messager[key].apply($.messager, args);
            }
        });
    }

    /**
     * 获取方法的Key数据
     */
    private getMethodKeys():Array<string>{
        let methodKeys = new Array<string>();
        Object.getOwnPropertyNames($.messager).forEach((key)=>{
            if(key != 'defaults'){
                methodKeys.push(key);
            }
        });
        return methodKeys;
    }
    public paint(options:any){
        let opts = this.createOptions(options);
        $.extend($.messager.defaults, opts);
    }
    public repaint(options: any) {  
        this.paint(options);
    }
}   